import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { IsNotEmpty, IsNumber } from 'class-validator';
import { Init } from 'src/common/entities/init.entity';

@Entity({
  comment: '订单表',
})
export class Order extends Init {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'varchar',
    length: 255,
    comment: '订单编号',
  })
  @IsNotEmpty({
    message: '订单编号不能为空',
  })
  orderNo: string;

  @Column({
    type: 'decimal',
    precision: 10,
    scale: 2,
    comment: '订单总价',
  })
  @IsNotEmpty({
    message: '订单总价不能为空',
  })
  @IsNumber({}, { message: '订单总价必须是数字' })
  totalPrice: number;

  @Column({
    type: 'timestamp',
    comment: '下单时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  @IsNotEmpty({
    message: '下单时间不能为空',
  })
  orderTime: Date;

  @Column({
    type: 'int',
    comment: '订单状态 1:待支付 2:已支付 3:已发货 4:已完成 5:已取消',
  })
  orderStatus: OrderStatusEnum;

  @Column({
    type: 'int',
    comment: '商品id',
  })
  goodsId: number;

  @Column({
    type: 'int',
    comment: '商品数量',
  })
  goodsQuantity: number;

  @Column({
    type: 'decimal',
    precision: 10,
    scale: 2,
    comment: '商品价格',
  })
  goodsPrice: number;
}

export enum OrderStatusEnum {
  PENDING_PAY = 1, // 待支付
  PAID_PAY = 2, // 已支付
  SHIPPED = 3, // 已发货
  COMPLETED = 4, // 已完成
  CANCELED = 5, // 已取消
}
